<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../static/Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../static/Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../static/Css/style.css" />
    <link rel="stylesheet" type="text/css" href="../static/layui/css/layui.css"/>
    <script type="text/javascript" src="../static/Js/jquery.js"></script>
    <script type="text/javascript" src="../static/Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../static/Js/bootstrap.js"></script>
    <script type="text/javascript" src="../static/Js/ckform.js"></script>
    <script type="text/javascript" src="../static/Js/common.js"></script>
    <!-- <script type="text/javascript" src="../static/layui/layui.js"></script> -->
    <script type="text/javascript" src="../static/layer/layer.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
        th,td{
			text-align:center;
        }
        .prod{
        	margin: 0px 5px;
    		background-color: orangered;
    		border: none;
    		color: white;
        }
        .prod_div1{
            box-shadow: 0px 5px 5px rgba(0,0,0,0.1);
    		line-height: 50px;
    	}
    		
    	#prodSearchInput{
    	    line-height: 30px;
    		width: 255px;
    		margin: 0px 15px;
    		text-indent: 15px;
    	}


    </style>
</head>
<body>
	<div class="prod_div1">
	    <input  type="text" id="prodSearchInput" placeholder="输入工艺名称进行查询" class="abc input-default" value="">&nbsp;&nbsp;  
    	<button type="button" id="prodSearchParams" class="btn btn-primary">查询</button>&nbsp;&nbsp; 
    	<button type="button" class="btn btn-success" id="addProduction">制定工艺</button>
	</div>   
	
	<table class="table table-bordered table-hover definewidth m10" >
		<colgroup>
	    	<col width="15%">
	    	<col width="15%">
	    	<col width="10%">
	    	<col width="20%">
	    	<col width="20%">
	    	<col width="15%">
	  	</colgroup>
    	<thead>
    		<tr>
		        <th>工艺名称</th>
		        <th>使用材料</th>
		        <th>使用数量</th>
		        <th>开始时间</th>
		        <th>创建时间</th>
		        <th>操作</th>
	    	</tr>
	    </thead>
	    <tbody id="prodTbody"></tbody>
	</table>
<!-- <div class="inline pull-right page">
         </div> -->
</body>
</html>
<script type="text/javascript">
	
	$(document).ready(function(){
		var searchContent = $("#prodSearchInput").val();
		getProductionList(searchContent);
	});
	
	function getProductionList(searchContent){
		$.ajax({
			type:"post",
			dataType:"json",
			url:"/productions/getProductionList",
			data:{"content":searchContent},
			success:function(result){
				if(result.ret == 1){
					var pl = result.list;
					$("#prodTbody").empty();
					for(var i = 0 ;i < pl.length; i++){
	                    var prod = pl[i];
	                    var str = "<tr class='prod_"+prod.id+"'>";
	                    str += "<td>"+prod.name+"</td>";
	                    str += "<td>"+prod.rawmaterialName+"</td>";
	                    str += "<td>"+prod.num+"</td>";
	                    var wtime = new Date(parseInt(prod.workTime)).toLocaleString().replace(/:\d{1,2}$/,' ');
	                    str += "<td>"+wtime+"</td>";
	                    var time = new Date(parseInt(prod.createDate)).toLocaleString().replace(/:\d{1,2}$/,' ');
	                    str += "<td class='time'>"+time+"</td>";
	                    str += "<td>";
	                    str += "<button value='"+prod.id+"' class='btn btn-primary prod prodDel'>删除</button>";
	                    //str += "<button value='"+order.id+"' class='btn btn-primary ord ordEdit' style='background:#2196f3'>修改</button>";
	                    //str += "<button value='"+order.id+"' class='btn btn-primary ord downOrder' style='background:#3f51b5'>下单</button>";
	                    //<button type="button" id="cusSearchParams" class="btn btn-primary">查询</button>
	                    str += "</td>";
	                    str += "</tr>";
	                    $("#prodTbody").append(str);
		    		}
				}else{
					ErrTips(result.msg);
				}
			},
			error:function(result){
				ErrTips("服务器错误");
			}
		})
	};
	
	$("#prodSearchParams").on('click',function(){
		var searchContent = $("#prodSearchInput").val();
		if($.trim(searchContent) == ""){
	   		ErrTips("搜索内容不能为空");
	        return;
	    }
		getProductionList(searchContent);
		
	})
	
	$("#addProduction").on('click',function(){
		window.location.href = "add";
	})
	
	$(document).on('click','.prodDel',function () {
		var prodId = $(this).attr('value');
		layer.confirm('确认删除吗？', {
			icon:3,
			btn: ['确定','取消'] //按钮
			}, function(){
				deleteProduction(prodId);
			});
	});
	
	function deleteProduction(prodId){
		$.ajax({
	      	type:"post",
	      	dataType:"json",
	      	url:"/productions/deleteProduction",
	      	data:{"id":prodId},	
	      	success:function(result){
	            if(result.ret == 1){
	            	TureTips(result.msg);
	            	$(".prod_"+prodId).remove();
	            }else{
	            	ErrTips(result.msg);
	            }
	          },
	          error:function(result){
	        	  ErrTips("服务器错误");
	          }
	      })
	};


	function ErrTips(msg) {
		layer.msg(msg,{icon:7,time:1000});
    }
	
	function TureTips(msg) {
		layer.msg(msg,{icon:1,time:1500});
	}

</script>